<?php
echo $html->script(array("jquery.pagination.js", "jquery-ui.js", "smartrollover.js"));
?>
<?php $this->Html->addCrumb('Advance Search Results'); ?>
<script type="text/javascript">

    // This is a very simple demo that shows how a range of elements can
    // be paginated.
    // The elements that will be displayed are in a hidden DIV and are
    // cloned for display. The elements are static, there are no Ajax
    // calls involved.

    /**
     * Callback function that displays the content.
     *
     * Gets called every time the user clicks on a pagination link.
     *
     * @param {int} page_index New Page index
     * @param {jQuery} jq the container with the pagination links as a jQuery object
     */
    function pageselectCallback(page_index, jq, items_per_page){
        page_index = page_index ==0 ? 1 : (page_index+1);
        var startIndex = parseInt(((page_index - 1) * items_per_page));
        var endIndex = parseInt(((page_index) * items_per_page));
        jQuery('#Searchresult ul').empty();
        jQuery('#hiddenresult ul li').each(function(i,obj){
            if(startIndex <= i && i < endIndex ){
                var new_content = jQuery(obj).clone();
                jQuery('#Searchresult ul').append(new_content);
            }
        });
        var totalPage = 0;
        try{
            totalPage = Math.ceil(parseInt(jQuery('#hiddenresult ul li').size())/items_per_page);
        }catch(ex){

        }
        jQuery('#pagePositionNum').empty().html('Page '+page_index+' of '+totalPage);
        return false;
    }

    // When document is ready, initialize pagination
    jQuery(document).ready(function(){
        jQuery('#viewNumPageItem ul li a').live('click',function(){
            var $href = jQuery(this).attr('href');
            $href = parseInt($href.replace('#',''));
            // count entries inside the hidden content
            var num_entries = jQuery('#hiddenresult ul li').length;
            // Create content inside pagination element
            jQuery("#Pagination").empty().pagination(num_entries, {
                callback: pageselectCallback,
                items_per_page: $href // Show only one item per page
            });
            jQuery(this).closest('ul').find('li span').each(function(i,$this){
                var pageNum = jQuery(this).html();
                jQuery(this).closest('li').empty().html('<a href="#'+pageNum+'">'+pageNum+'</a>');
            });
            jQuery(this).closest('li').empty().html('<span>'+$href+'</span>');
            return false;
        }).eq(0).trigger('click') ;

        jQuery('#gotoPage button').click(function(){
            var $pageNum = parseInt(jQuery('#gotoPage input[type=text]').val());
            $pageNum = $pageNum - 1;
            jQuery("#Pagination").trigger('setPage', [$pageNum]);
        });
        //initPagination();
    });
</script>
<!--[if lt IE 7]>
<script type="text/javascript" src="js/DD_belatedPNG.js"></script>
<script>
  DD_belatedPNG.fix('img,div');
</script>


<![endif]-->

<script type="text/javascript">
    jQuery(document).ready(function(){

        jQuery("a.switch_thumb").toggle(function(){
            jQuery(this).addClass("swap");
            jQuery("ul.display").fadeOut("fast", function() {
                jQuery(this).fadeIn("fast",function(){
                    jQuery(this).find('.content_block p').each(function(){
                        jQuery(this).find('span:eq(0)').appendTo(jQuery(this));
                    });
                }).addClass("thumb_view");
            });
        }, function () {
            jQuery(this).removeClass("swap");
            jQuery("ul.display").fadeOut("fast", function() {
                jQuery(this).fadeIn("fast",function(){
                    jQuery(this).find('.content_block p').each(function(){
                        jQuery(this).find('span:last').prependTo(jQuery(this));
                    });
                }).removeClass("thumb_view");


            });
        });

    });
</script>
<div class="products">
    <div class="search-title"><?php __('BROWSE & SEARCH'); ?>
    </div>
    <div class="rht-con">
        <div class="mdl-con widthstyle1" style=" width: 100%;">
            <div class="porduct-browse" style=" width: 100%;">
                <div class="search_result">Showing results for<i style="color: #2200C1;">
                        <?php
                        echo '"' . $searchkey . '".';
                        ?>
                    </i>
                </div>
                <p><?php
                        if (!empty($products)) {
                            echo count($products);
                        } else {
                            echo '0';
                        }
                        ?> results found.</p>
                <?php
                if (!empty($products)) {
                    ?>
                    <div class="result">
                        <div class="container">
                            <?php if (empty($thumb)) { ?>
                                <a href="<?php echo Configure::read('base_url') . 'products/advance_search/' . $searchkey . '/thumb'; ?>" class="switch_thumb1">Switch Thumb</a>
                            <?php } else { ?>
                                <a href="<?php echo Configure::read('base_url') . 'products/advance_search/' . $searchkey; ?>" class="switch_thumb1 swap">Switch Thumb</a>
                            <?php } ?>
                            <div id="Searchresult">
                                <?php if (empty($thumb)) { ?>
                                    <div class="days_left"><span style="text-align:center; margin-left: 185px;"><b>Title</b></span><span style="text-align:right; margin-left: 565px;margin-right:50px;"><b>ID</b></span><b>Price</b><b style="margin-left:60px">Days Left</b></div>
                                    <ul class="display"></ul>
                                <?php } else { ?>	
                                    <ul class="display thumb_view"></ul>
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <!-- Container element for all the Elements that are to be paginated -->
                    <div id="hiddenresult" style="display:none;">
                        <ul class="display">
                            <?php
                            if (!empty($products)) {
                                $i = 0;
                                foreach ($products as $product):
                                    $class = null;
                                    if ($i++ % 2 == 0) {
                                        $class = ' class="altrow"';
                                    }
                                    ?>
                                    <li>
                                        <div class="content_block">
                                            <div><a href="javascript:void(0);" alignLeft="1" controller="products" action="gallery_popup" ElmID="<?php echo $product['Product']['id']; ?>" onmouseover="showPop1(this)">
                                                    <?php
                                                    $image = "thumbs/";
                                                    echo $html->image($image . $thumbnail->render($product['Product']['products_thumbnailImage'], array('path' => 'thumbs', 'width' => 140, 'height' => 140, 'quality' => 80)
                                                            ), array('alt' => $product['Product']['products_title'])
                                                    );
                                                    ?>
                                                </a>
                                            </div>

                                            <?php if (empty($thumb))
                                                echo"<h2>";else
                                                echo"<h2 style='width:240px;'>"; ?><a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $product['Product']['id']; ?>"><?php echo $product['Product']['products_title']; ?></a></h2>
                                            <p><span><a href="<?php echo Configure::read('base_url');?>products/store/<?php echo $product['Product']['user_id']; ?>"><?php echo $product['User']['username'];?></a></span> <span><?php echo 'US $' . $product['Product']['products_price']; ?></span> <span><?php echo $product[0]['totaldays']; ?>days</span></p>
                                        </div>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                            <?php
                        }else {
                            echo 'Not data Found!';
                        }
                        ?>
                    </div>
                    <div id="viewNumPageItem">
                        <span style="float:left; display:block;">Items per page:&nbsp;&nbsp;</span>
                        <ul class="newinline">
                            <li><a href="#25" >25</a></li>
                            <?php
                            if (count($products) >= 50) {
                                ?>
                                <li><a href="#50" >50</a></li>
                                <?php
                            }
                            ?>
                            <?php
                            if (count($products) >= 100) {
                                ?>
                                <li><a href="#100" >100</a></li>
                                <?php
                            }
                            if (count($products) >= 200) {
                                ?>
                                <li><a href="#200" >200</a></li>
                                <?php
                            }
                            ?>
                        </ul>
                    </div>
                    <div class="clear"></div>
                    <div id="pagePositionNum"></div>
                    <div id="Pagination"></div>
                    <div id="gotoPage">
                        <input type="text" size="10" />
                        <button value="Go" >Go</button>
                    </div>
                    <?php
                }
                ?>
                <div class="clear"></div>
            </div>


        </div>
        <!--Start slider--><!--End Slider-->

    </div>              
    <div class="paging">
    </div>
</div>
<style type="text/css">
    th,th a{font-size:14px; font-weight:700; text-decoration:none;}
</style>			
<?php echo $this->element('home/browse_search_js'); ?>